package com.estore.service;

import com.estore.model.Product;
import java.util.HashMap;
import java.util.Map;

public class ProductService {
    private final Map<String, Product> productData; // 标记为final

    public ProductService() {
        productData = new HashMap<>();
        // 初始化商品数据
        productData.put("P001", new Product("P001", "Java编程思想", 108.0, 50));
        productData.put("P002", new Product("P002", "Python数据分析", 89.0, 30));
        productData.put("P003", new Product("P003", "无线鼠标", 69.9, 100));
        productData.put("P004", new Product("P004", "机械键盘", 299.0, 40));
        productData.put("P005", new Product("P005", "保温杯", 59.0, 70));
        productData.put("P006", new Product("P006", "笔记本", 15.0, 200));
        productData.put("P007", new Product("P007", "蓝牙耳机", 199.0, 60));
    }

    public Map<String, Product> getAllProducts() {
        return new HashMap<>(productData);
    }

    // 消除“方法'findProductById'从未使用”：实际在客户端用“getAllProducts+遍历”替代，可删除此方法
    // public Product findProductById(String id) {
    //     return productData.get(id);
    // }
}